﻿using CxSoft.IntegralManager.Configuration;
using CxSoft.IntegralManager.Web;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.Configuration;

namespace CxSoft.IntegralManager.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class IntegralManagerDbContextFactory : IDbContextFactory<IntegralManagerDbContext>
    {
        public IntegralManagerDbContext Create(DbContextFactoryOptions options)
        {
            var builder = new DbContextOptionsBuilder<IntegralManagerDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            IntegralManagerDbContextConfigurer.Configure(builder, configuration.GetConnectionString(IntegralManagerConsts.ConnectionStringName));
            
            return new IntegralManagerDbContext(builder.Options);
        }
    }
}